import axios from 'axios';
import { getApigatewayHost, json2formdata } from '../../../utils';

/**
 * 图片上传
 */
export default (file) => (
    new Promise((resolve, reject) => {
        const params = {
            item_name: 'v',
            file_name: file.name,
            file_type: 'file',
            file: file
        }

        axios.post(
            `${getApigatewayHost()}/base/v1/upload/upload`,
            json2formdata(params)
        ).then((res: any) => {
            const { status, info, result} = res.data
            if (!status) {
                resolve(result);
            }else {
                reject(info)
            }
        }).catch(e => {
            reject(e.toString())
        })
    })
)